# Maintainer: hauptmech # Contributor: figo.zhang, chubtuff, lubosz
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>
#
# Matlab bindings are not built by default to reduce dependencies.

_realname=gl2ps
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.4.2
pkgrel=1
pkgdesc="an OpenGL to PostScript printing library (mingw-w64)"
arch=('any')
url='https://geuz.org/gl2ps/'
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-libpng")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://geuz.org/gl2ps/src/gl2ps-${pkgver}.tgz"
        "0001-MSYS2-FHS-layout.patch")
sha256sums=('8d1c00c1018f96b4b97655482e57dcb0ce42ae2f1d349cd6d4191e7848d9ffe9'
            '17815c4ba80f90744a149bb130a5e06fc4e3489681ad180562b42f67d159839b')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-MSYS2-FHS-layout.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DMATH_LIBRARY=${MINGW_PREFIX}/${MINGW_CHOST}/lib/libm.a \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING.LGPL   ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LGPL
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING.GL2PS  ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.GL2PS
}
